<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   深入浅出数据仓库中SQL性能优化之MySQL篇  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/7603.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466459289: Accept with keywords: (title(0.333333333333):社区,数据仓库,性能,中,数盟,优化, topn(0.266666666667):语文,开发人员,网格,时间,代价,实际,结果,关联,计划,基础架构,计算,文章,情况,日志,排序,数据,报表,性能,用户,数盟,问题,小张,优化,主键,顺序,编程语言,数据仓库,字段,数据量,时候).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    深入浅出数据仓库中SQL性能优化之MySQL篇
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    深入浅出数据仓库中SQL性能优化之MySQL篇 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,70] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/base">
       基础架构
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/7603.html">
          深入浅出数据仓库中SQL性能优化之MySQL篇
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,810 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/base" rel="category tag">
          基础架构
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        作者：
        <a href="http://sunyi514.github.io/2013/04/30/%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93%E4%B8%AD%E7%9A%84sql%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%EF%BC%88mysql%E7%AF%87%EF%BC%89/">
         肥男爱肉
        </a>
       </p>
       <p>
        做数据仓库的头两年，使用高配置单机 + MySQL的方式来实现所有的计算（包括数据的ETL，以及报表计算。没有OLAP）。用过MySQL自带的MYISAM和列存储引擎Infobright。这篇文章总结了自己和团队在那段时间碰到的一些常见性能问题和解决方案。
       </p>
       <p>
        P.S.如果没有特别指出，下面说的mysql都是指用MYISAM做存储引擎。
       </p>
       <h1 id="利用已有数据，避免重复计算">
        利用已有数据，避免重复计算
       </h1>
       <p>
        业务需求中往往有计算一周/一个月的某某数据，比如计算最近一周某个特定页面的PV/UV。这里出现的问题就是实现的时候直接取整周的日志数据，然后进行计算。这样其实就出现了重复计算，某一天的数据在不同的日子里被重复计算了7次。
       </p>
       <p>
        解决办法非常之简单，就是把计算进行切分，如果是算PV，做法就是每天算好当天的PV，那么一周的PV就把算好的7天的PV相加。如果是算UV，那么每天从日志数据取出相应的访客数据，把最近七天的访客数据单独保存在一个表里面，计算周UV的时候直接用这个表做计算，而不需要从原始日志数据中抓上一大把数据来算了。
       </p>
       <p>
        这是一个非常简单的问题，甚至不需要多少SQL的知识，但是在开发过程中往往被视而不见。这就是只实现业务而忽略性能的表现。从小规模数据仓库做起的工程师，如果缺乏这方面的意识和做事规范，就容易出现这种问题，等到数据仓库的数据量变得比较大的时候，才会发现。
       </p>
       <h1 id="case_when关键字的使用方法">
        case when关键字的使用方法
       </h1>
       <p>
        <code>
         case when
        </code>
        这个关键字，在做聚合的时候，可以很方便的将一份数据在一个SQL语句中进行分类的统计。举个例子，比如下面有一张成绩表(表名定为
        <code>
         scores
        </code>
        )：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           name
          </th>
          <th>
           course
          </th>
          <th>
           score
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           小明
          </td>
          <td>
           语文
          </td>
          <td>
           90
          </td>
         </tr>
         <tr>
          <td>
           小张
          </td>
          <td>
           语文
          </td>
          <td>
           94
          </td>
         </tr>
         <tr>
          <td>
           小红
          </td>
          <td>
           语文
          </td>
          <td>
           95
          </td>
         </tr>
         <tr>
          <td>
           小明
          </td>
          <td>
           数学
          </td>
          <td>
           96
          </td>
         </tr>
         <tr>
          <td>
           小张
          </td>
          <td>
           数学
          </td>
          <td>
           98
          </td>
         </tr>
         <tr>
          <td>
           小红
          </td>
          <td>
           数学
          </td>
          <td>
           94
          </td>
         </tr>
         <tr>
          <td>
           小明
          </td>
          <td>
           英语
          </td>
          <td>
           99
          </td>
         </tr>
         <tr>
          <td>
           小张
          </td>
          <td>
           英语
          </td>
          <td>
           96
          </td>
         </tr>
         <tr>
          <td>
           小红
          </td>
          <td>
           英语
          </td>
          <td>
           93
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        现在需要统计小张的平均成绩，小明的平均成绩和小明的语文成绩。SQL实现如下：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491435290990059" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
6
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491435290990059-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491435290990059-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491435290990059-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491435290990059-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491435290990059-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491435290990059-6">
                    6
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491435290990059-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491435290990059-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491435290990059-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491435290990059-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491435290990059-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491435290990059-6">
                    <span class="crayon-cn">
                     6
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0007 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491442650966900" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; 
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小张'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) &lt;span class="keyword"&gt;as&lt;/span&gt; xz_avg_score,
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小明'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) &lt;span class="keyword"&gt;as&lt;/span&gt; xm_avg_score,
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小明'&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; course = &lt;span class="string"&gt;'语文'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) 
&lt;span class="keyword"&gt;as&lt;/span&gt; xm_yuwen_score 
&lt;span class="keyword"&gt;from&lt;/span&gt; scores;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491442650966900-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491442650966900-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491442650966900-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491442650966900-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491442650966900-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491442650966900-6">
                    6
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491442650966900-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491442650966900-2">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小张'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xz_avg_score
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491442650966900-3">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小明'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xm_avg_score
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491442650966900-4">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小明'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     course
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '语文'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491442650966900-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xm_yuwen_score
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491442650966900-6">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     scores
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0240 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        如果现在这个成绩表有1200万条的数据，包含了400万的名字 * 3个科目，上面的计算需要多长时间？我做了一个简单的测试，答案是5.5秒。
       </p>
       <p>
        而如果我们把sql改成下面的写法：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949144a532717204" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
6
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949144a532717204-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949144a532717204-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949144a532717204-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949144a532717204-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949144a532717204-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949144a532717204-6">
                    6
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949144a532717204-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949144a532717204-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949144a532717204-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949144a532717204-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949144a532717204-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949144a532717204-6">
                    <span class="crayon-cn">
                     6
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0007 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491450204646490" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; 
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小张'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) &lt;span class="keyword"&gt;as&lt;/span&gt; xz_avg_score,
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小明'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) &lt;span class="keyword"&gt;as&lt;/span&gt; xm_avg_score,
       &lt;span class="aggregate"&gt;avg&lt;/span&gt; (&lt;span class="keyword"&gt;case&lt;/span&gt; &lt;span class="keyword"&gt;when&lt;/span&gt; name =&lt;span class="string"&gt;'小明'&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; course = &lt;span class="string"&gt;'语文'&lt;/span&gt; &lt;span class="keyword"&gt;then&lt;/span&gt; score &lt;span class="keyword"&gt;end&lt;/span&gt;) 
&lt;span class="keyword"&gt;as&lt;/span&gt; xm_yuwen_score 
&lt;span class="keyword"&gt;from&lt;/span&gt; scores &lt;span class="keyword"&gt;where&lt;/span&gt; name &lt;span class="keyword"&gt;in&lt;/span&gt; (&lt;span class="string"&gt;'小张'&lt;/span&gt;, &lt;span class="string"&gt;'小明'&lt;/span&gt;);&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491450204646490-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491450204646490-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491450204646490-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491450204646490-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491450204646490-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491450204646490-6">
                    6
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491450204646490-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491450204646490-2">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小张'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xz_avg_score
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491450204646490-3">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小明'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xm_avg_score
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491450204646490-4">
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     avg
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     case
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     when
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小明'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     course
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '语文'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     then
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     score
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     end
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491450204646490-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     xm_yuwen_score
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491450204646490-6">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     scores
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     name
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     in
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小张'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '小明'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0248 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        这样的话，只需要3.3秒就能完成。
       </p>
       <p>
        之所以后面一种写法总是比前面一种写法快，不同之处就在于是否先在
        <code>
         where
        </code>
        里面把数据过滤掉。前一种写法扫描了三遍全表的数据（做一个
        <code>
         case when
        </code>
        扫一遍），后面的写法扫描一遍全表，把数据过滤了之后，
        <code>
         case when
        </code>
        就不用过这么多数据量了。
       </p>
       <p>
        跟进一步说，如果在name字段上有索引，那么后一种写法将会更快，测试结果只用0.05秒，而前面一种情况，sql优化器是判断不出来能用索引的，时间依然是5.5秒。
       </p>
       <p>
        在实际工作中，开发经常只是为了实现功能逻辑，而习惯了在
        <code>
         case when
        </code>
        中限制条件取数据。这样在出现类似例子中的需求时，没有把应该限制的条件写到
        <code>
         where
        </code>
        里面。这是在实际代码中发现最多的一类问题。
       </p>
       <h1 id="分页取数方式">
        分页取数方式
       </h1>
       <p>
        在数据仓库中有一个重要的基础步骤，就是对数据进行清洗。比如数据源的数据如果以JSON方式存储，在mysql的数据仓库就必须将json中需要的字段提取出来，做成单独的表字段。这个步骤用sql直接处理很麻烦，所以可以用主流编程语言（比如java）的json库进行解析。解析的时候需要读取数据，一次性读取进来是不可能的，所以要分批读取（相当于分页了）。
       </p>
       <p>
        最初的实现方式就是标记住每次取数据的偏移量，然后一批批读取：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491458302130946" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491458302130946-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491458302130946-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491458302130946-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491458302130946-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491458302130946-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491458302130946-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491458302130946-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491458302130946-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491458302130946-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491458302130946-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0006 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949145e550232333" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t limit &lt;span class="number"&gt;10000&lt;/span&gt;,&lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t limit &lt;span class="number"&gt;20000&lt;/span&gt;,&lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t limit &lt;span class="number"&gt;30000&lt;/span&gt;,&lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="comment"&gt;/*略去很多行……*/&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t limit &lt;span class="number"&gt;990000&lt;/span&gt;,&lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949145e550232333-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949145e550232333-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949145e550232333-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949145e550232333-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949145e550232333-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949145e550232333-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949145e550232333-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     20000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949145e550232333-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     30000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949145e550232333-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "comment"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-c">
                     /*略去很多行……*/
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949145e550232333-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     990000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0151 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        这样的代码，在开始几句sql的时候执行速度还行，但是到后面会越来越慢，因为每次要读取大量数据再丢弃，其实是一种浪费。
       </p>
       <p>
        高效的实现方式，可以是用表中的主键进行分页。如果数据是按照主键排序的，那么可以是这样（这么做是要求主键的取值序列是连续的。假设主键的取值序列我们比较清楚，是从10001-1000000的连续值）：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491465847739241" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491465847739241-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491465847739241-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491465847739241-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491465847739241-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491465847739241-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491465847739241-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491465847739241-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491465847739241-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491465847739241-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491465847739241-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0007 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949146a242788328" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;10000&lt;/span&gt; limit &lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;20000&lt;/span&gt; limit &lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;30000&lt;/span&gt; limit &lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="comment"&gt;/*略去很多行……*/&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;990000&lt;/span&gt; limit &lt;span class="number"&gt;10000&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949146a242788328-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949146a242788328-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949146a242788328-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949146a242788328-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949146a242788328-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949146a242788328-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949146a242788328-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     20000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949146a242788328-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     30000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949146a242788328-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "comment"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-c">
                     /*略去很多行……*/
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949146a242788328-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     990000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     limit
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0256 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        就算数据不是按主键排序的，也可以通过限制主键的范围来分页。这样处理的话，主键的取值序列不连续也没有太大问题，就是每次拿到的数据会比理想中的少一些，反正是用在数据处理，不影响正确性：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491471582086745" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491471582086745-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491471582086745-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491471582086745-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491471582086745-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491471582086745-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491471582086745-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491471582086745-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491471582086745-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491471582086745-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491471582086745-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0006 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491477406784798" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;10000&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; t.id &amp;lt;= &lt;span class="number"&gt;20000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;20000&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; t.id &amp;lt;= &lt;span class="number"&gt;30000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;30000&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; t.id &amp;lt;= &lt;span class="number"&gt;40000&lt;/span&gt;;&lt;/span&gt;
&lt;span class="comment"&gt;/*略去很多行……*/&lt;/span&gt;
&lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; json_obj &lt;span class="keyword"&gt;from&lt;/span&gt; t &lt;span class="keyword"&gt;where&lt;/span&gt; t.id &amp;gt; &lt;span class="number"&gt;990000&lt;/span&gt; &lt;span class="keyword"&gt;and&lt;/span&gt; t.id &amp;lt;= &lt;span class="number"&gt;1000000&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491477406784798-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491477406784798-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491477406784798-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491477406784798-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491477406784798-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491477406784798-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     10000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     lt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     20000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491477406784798-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     20000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     lt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     30000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491477406784798-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     30000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     lt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     40000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491477406784798-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "comment"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-c">
                     /*略去很多行……*/
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491477406784798-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     json_obj
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     990000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     and
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     t
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     lt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1000000
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0327 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        这样的话，由于主键上面有索引，取数据速度就不会受到数据的具体位置的影响了。
       </p>
       <h1 id="索引使用">
        索引使用
       </h1>
       <p>
        索引的使用是关系数据库的SQL优化中一个非常重要的主题，也是一个常识性的东西。但是工程师在实际开发中往往是加完索引就觉得万事大吉了，也不去检查索引是否被正确的使用了，所以会经常出一些瞎猫碰到死耗子或者是似是而非的情况。
       </p>
       <h2 id="索引调整">
        索引调整
       </h2>
       <p>
        前面说到开发人员在对索引的了解似是而非的时候只知道要加索引，而不知道为什么加。
       </p>
       <p>
        比如现在有一个数据集，对应非常常见的网站统计场景。这个数据集有两个表组成，其中一个是流量表
        <code>
         item_visits
        </code>
        ，每条记录表示某一个商品（item）被访问了一次，包括访问者的一些信息，比如用户id，用户名等等，有将近800万条数据。示例如下：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           item_id
          </th>
          <th>
           visitor_id
          </th>
          <th>
           visitor_name
          </th>
          <th>
           visitor_city
          </th>
          <th>
           url
          </th>
          <th>
           ……
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           1
          </td>
          <td>
           55
          </td>
          <td>
           用户001
          </td>
          <td>
           1
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           10
          </td>
          <td>
           245
          </td>
          <td>
           用户002
          </td>
          <td>
           2
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           3
          </td>
          <td>
           2
          </td>
          <td>
           用户003
          </td>
          <td>
           1
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           10
          </td>
          <td>
           148
          </td>
          <td>
           用户004
          </td>
          <td>
           3
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           3
          </td>
          <td>
           75
          </td>
          <td>
           用户005
          </td>
          <td>
           4
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           7
          </td>
          <td>
           422
          </td>
          <td>
           用户006
          </td>
          <td>
           4
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           3
          </td>
          <td>
           10
          </td>
          <td>
           用户007
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        另一个表是商品表
        <code>
         items
        </code>
        ，包含1200多种商品，字段有商品名字和所属种类：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           item_id
          </th>
          <th>
           item_name
          </th>
          <th>
           item_type
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           1
          </td>
          <td>
           毛巾
          </td>
          <td>
           生活用品
          </td>
         </tr>
         <tr>
          <td>
           2
          </td>
          <td>
           脸盆
          </td>
          <td>
           生活用品
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        现在有一个需求，计算每个商品种类（item_type）被访问的次数。sql的实现不难：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949147f258709478" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949147f258709478-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949147f258709478-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949147f258709478-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949147f258709478-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949147f258709478-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949147f258709478-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949147f258709478-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949147f258709478-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0006 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491485734845913" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; item_type, &lt;span class="aggregate"&gt;count&lt;/span&gt;(*) &lt;span class="keyword"&gt;as&lt;/span&gt; visit_num
&lt;span class="keyword"&gt;from&lt;/span&gt; items a
&lt;span class="keyword"&gt;join&lt;/span&gt; item_visit b &lt;span class="keyword"&gt;using&lt;/span&gt; (item_id)
&lt;span class="keyword"&gt;group&lt;/span&gt; &lt;span class="keyword"&gt;by&lt;/span&gt; item_type;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491485734845913-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491485734845913-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491485734845913-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491485734845913-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491485734845913-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     visit_num
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491485734845913-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     items
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491485734845913-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    visit
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     item_id
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491485734845913-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     group
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     by
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0046 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        开发人员知道，在join的时候，其中的一个表的join key要加索引，然后他发现
        <code>
         visit
        </code>
        表在
        <code>
         item_id
        </code>
        字段上已经有索引了，所以就打完收工了。到这里为止一切都没有问题。但是后来这个需求有改动，需要限制用户的城市是某个固定城市，比如
        <code>
         visitor_city = 1
        </code>
        ，那么显然sql变成了：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949148b860000369" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949148b860000369-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949148b860000369-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949148b860000369-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949148b860000369-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949148b860000369-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949148b860000369-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949148b860000369-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949148b860000369-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949148b860000369-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949148b860000369-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0005 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491491149104526" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; item_type, &lt;span class="aggregate"&gt;count&lt;/span&gt;(*) &lt;span class="keyword"&gt;as&lt;/span&gt; visit_num
&lt;span class="keyword"&gt;from&lt;/span&gt; items a
&lt;span class="keyword"&gt;join&lt;/span&gt; item_visit b &lt;span class="keyword"&gt;using&lt;/span&gt; (item_id)
&lt;span class="keyword"&gt;where&lt;/span&gt; visitor_city = &lt;span class="number"&gt;1&lt;/span&gt;
&lt;span class="keyword"&gt;group&lt;/span&gt; &lt;span class="keyword"&gt;by&lt;/span&gt; item_type;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491491149104526-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491491149104526-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491491149104526-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491491149104526-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491491149104526-5">
                    5
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491491149104526-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     visit_num
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491491149104526-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     items
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491491149104526-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    visit
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     item_id
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491491149104526-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     visitor_city
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491491149104526-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     group
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     by
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0052 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        开发人员按照需求修改sql之后对于索引的调整无动于衷，因为他觉得，我已经用上索引了呀。而实际上很明显的，只需要在
        <code>
         visitor_city
        </code>
        和
        <code>
         items
        </code>
        表的
        <code>
         item_id
        </code>
        上都加上索引，就能极大的减少时间。原因就在于开发人员“感觉”能用上索引，而且开发阶段试运行时间没问题就OK，并不关心是不是有更好的索引使用方式，甚至不确认是否用上了索引。在这样的一个真实案例中，原有的sql在后期出现了运行缓慢的现象，才逐渐被发掘出问题。
       </p>
       <h2 id="覆盖索引">
        覆盖索引
       </h2>
       <p>
        针对上面那个需求（不限制city），假设现在两个表的的item_id字段都有索引，而且把
        <code>
         count(*)
        </code>
        换成
        <code>
         count(visitor_city)
        </code>
        ，还是会得到完全一样的结果，但是会对执行时间有什么影响？
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768649491498398001388" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-5768649491498398001388-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491498398001388-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-5768649491498398001388-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-5768649491498398001388-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-5768649491498398001388-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491498398001388-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-5768649491498398001388-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-5768649491498398001388-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0004 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576864949149d540574599" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; item_type, &lt;span class="aggregate"&gt;count&lt;/span&gt;(visitor_city) &lt;span class="keyword"&gt;as&lt;/span&gt; visit_num
&lt;span class="keyword"&gt;from&lt;/span&gt; items a
&lt;span class="keyword"&gt;join&lt;/span&gt; item_visit b &lt;span class="keyword"&gt;using&lt;/span&gt; (item_id)
&lt;span class="keyword"&gt;group&lt;/span&gt; &lt;span class="keyword"&gt;by&lt;/span&gt; item_type;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-576864949149d540574599-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949149d540574599-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-576864949149d540574599-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-576864949149d540574599-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-576864949149d540574599-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ,
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     visitor_city
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-st">
                     as
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     visit_num
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949149d540574599-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     items
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-576864949149d540574599-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    visit
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     item_id
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-576864949149d540574599-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     group
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     by
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     item_type
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0046 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        测试结果表明，
        <code>
         count(*)
        </code>
        版本用时57秒，
        <code>
         count(visitor_city)
        </code>
        版本用时70秒。原因在哪里？主要就在于
        <code>
         count(*)
        </code>
        版本中
        <code>
         item_visits
        </code>
        表只需要用到
        <code>
         item_id
        </code>
        ，所以可以直接用索引来代替数据访问，这就是覆盖索引。
        <br/>
        在实际开发中，一方面要创造使用覆盖索引的机会，不要无谓的增加不需要的字段到查询语句中，上面的案例就是反面例子，实际开发中就有这样的情况发生。另一方面，根据具体的查询也要在成本允许的情况下构造覆盖索引，这样比普通的索引有更少的IO，自然有更快的访问速度。
       </p>
       <h2 id="强制索引">
        强制索引
       </h2>
       <p>
        有时候mysql的执行计划会不恰当的使用索引，这个时候就要求开发人员有一定的排查能力，并且根据实际情况调整索引。当然，这种情况还是比较少见的。Mysql用错索引的主要原因在于mysql是根据IO和CPU的代价来估算是否用索引，或者用哪种索引，而这个估算基于的统计信息有可能不准确。
       </p>
       <p>
        强制使用索引主要在两种场景下碰到。第一种是针对where过滤条件的索引，这个时候的语法是
        <code>
         force index (index_name)
        </code>
        。比如在ETL中常见的数据抽取，利用时间戳增量抽取当天新增或者更新的数据：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914a4405842120" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914a4405842120-1">
                    1
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914a4405842120-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0003 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914aa713020557" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; * &lt;span class="keyword"&gt;from&lt;/span&gt; &lt;span class="keyword"&gt;user&lt;/span&gt; &lt;span class="keyword"&gt;where&lt;/span&gt; update_timestamp &amp;gt;= curdate() – &lt;span class="number"&gt;1&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914aa713020557-1">
                    1
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914aa713020557-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     user
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     update_timestamp
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     curdate
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    –
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0032 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        一般在更新时间戳上会有索引，但是有时候mysql会判断出某一天的更新量特别大，比如超过了20%，那么根据数据的选择性，mysql决定不用索引。但实际上这个判断有可能是不准确的，如果表比较大而且在线上服务时间较长，还是有可能发生的，这个时候可以通过强制使用索引保证抽取的稳定性（当然，这要基于你对业务的了解，保证抽取量能维持在一个稳定的水平，不会发生超大更新量的情况）：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914b0200872922" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914b0200872922-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914b0200872922-2">
                    2
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914b0200872922-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914b0200872922-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0004 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914b6193978128" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; * &lt;span class="keyword"&gt;from&lt;/span&gt; &lt;span class="keyword"&gt;user&lt;/span&gt; force index (update_timestamp) 
&lt;span class="keyword"&gt;where&lt;/span&gt; update_timestamp &amp;gt;= curdate() – &lt;span class="number"&gt;1&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914b6193978128-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914b6193978128-2">
                    2
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914b6193978128-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     user
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     force
                    </span>
                    <span class="crayon-e">
                     index
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     update_timestamp
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914b6193978128-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     update_timestamp
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &amp;
                    </span>
                    <span class="crayon-v">
                     gt
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     curdate
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    –
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0034 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        强制使用索引的第二种情况，是join时对索引的选择。数据仓库中有时候会出现一种计算场景，对一个按日统计的报表中某一天的小部分数据进行更新。比如有一个按日统计的用户pv表（
        <code>
         user_pv_byday
        </code>
        ，一天约50万用户，表中有1个月数据，共1500万）：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           user_id
          </th>
          <th>
           pv
          </th>
          <th>
           stat_date
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           1
          </td>
          <td>
           10
          </td>
          <td>
           2013-01-01
          </td>
         </tr>
         <tr>
          <td>
           2
          </td>
          <td>
           15
          </td>
          <td>
           2013-01-01
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
         <tr>
          <td>
           1
          </td>
          <td>
           14
          </td>
          <td>
           2013-01-02
          </td>
         </tr>
         <tr>
          <td>
           2
          </td>
          <td>
           19
          </td>
          <td>
           2013-01-02
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        另一个表是当天小部分用户的pv表（
        <code>
         user_pv_to_update
        </code>
        ，1000条数据）：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           user_id
          </th>
          <th>
           pv
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           1
          </td>
          <td>
           18
          </td>
         </tr>
         <tr>
          <td>
           2
          </td>
          <td>
           20
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        两个表的索引情况是，
        <code>
         user_pv_byday
        </code>
        表的
        <code>
         user_id
        </code>
        和
        <code>
         stat_date
        </code>
        字段有索引，
        <code>
         user_pv_to_update
        </code>
        表的
        <code>
         user_id
        </code>
        字段有索引。
        <br/>
        现在要把
        <code>
         user_pv_to_update
        </code>
        的pv数据更新到
        <code>
         user_pv_byday
        </code>
        当天的数据中：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914bd309004724" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914bd309004724-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914bd309004724-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914bd309004724-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914bd309004724-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914bd309004724-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914bd309004724-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914bd309004724-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914bd309004724-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0005 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914c2518945695" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;update&lt;/span&gt; user_pv_byday a 
&lt;span class="keyword"&gt;join&lt;/span&gt; user_pv_to_update b &lt;span class="keyword"&gt;on&lt;/span&gt; a.user_id = b.user_id 
&lt;span class="keyword"&gt;set&lt;/span&gt; a.pv = b.pv
&lt;span class="keyword"&gt;where&lt;/span&gt; a.stat_date = curdate() – &lt;span class="number"&gt;1&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914c2518945695-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914c2518945695-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914c2518945695-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914c2518945695-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914c2518945695-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     update
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     user_pv
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    byday
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914c2518945695-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     user_pv_to
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    update
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     on
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     user_id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     user_id
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914c2518945695-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     set
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     pv
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     pv
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914c2518945695-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     stat_date
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     curdate
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    –
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0047 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        经过一段时间的线上运行之后，发现这个步骤越来越慢了。查了一下执行计划，发现mysql选择了
        <code>
         user_pv_byday
        </code>
        表的
        <code>
         user_id
        </code>
        做索引。于是，决定强制用上
        <code>
         stat_date
        </code>
        的索引。这样一来join的时候需要用到的就是
        <code>
         user_pv_to_update
        </code>
        上的
        <code>
         user_id
        </code>
        字段。这个时候就需要指定顺序，强制
        <code>
         user_pv_byday
        </code>
        表作为外层驱动表（
        <code>
         user_pv_to_update
        </code>
        则是nest loop的内层嵌套）：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914c9058949362" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914c9058949362-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914c9058949362-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914c9058949362-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914c9058949362-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914c9058949362-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914c9058949362-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914c9058949362-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914c9058949362-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0005 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914ce958971133" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               update user_pv_byday a 
straight_join user_pv_to_update b on a&lt;span class="preprocessor"&gt;.user&lt;/span&gt;_id = b&lt;span class="preprocessor"&gt;.user&lt;/span&gt;_id 
&lt;span class="keyword"&gt;set&lt;/span&gt; a&lt;span class="preprocessor"&gt;.pv&lt;/span&gt; = b&lt;span class="preprocessor"&gt;.pv&lt;/span&gt;
where a&lt;span class="preprocessor"&gt;.stat&lt;/span&gt;_date = curdate() – &lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="comment"&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914ce958971133-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914ce958971133-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914ce958971133-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914ce958971133-4">
                    4
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914ce958971133-1">
                    <span class="crayon-e">
                     update
                    </span>
                    <span class="crayon-v">
                     user_pv
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    byday
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     a
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914ce958971133-2">
                    <span class="crayon-e">
                     straight_join
                    </span>
                    <span class="crayon-v">
                     user_pv_to
                    </span>
                    <span class="crayon-sy">
                     _
                    </span>
                    update
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     b
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-i">
                     on
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "preprocessor"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     user
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     _id
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "preprocessor"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     user
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     _id
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914ce958971133-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     set
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "preprocessor"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     pv
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     b
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "preprocessor"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     pv
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914ce958971133-4">
                    <span class="crayon-i">
                     where
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     a
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "preprocessor"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     .
                    </span>
                    <span class="crayon-v">
                     stat
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     _date
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     curdate
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    –
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "number"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-cn">
                     1
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "comment"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0050 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        然后来看一下两种写法的执行计划。
       </p>
       <p>
        <strong>
         原有写法：
        </strong>
       </p>
       <table>
        <thead>
         <tr>
          <th>
           ……
          </th>
          <th>
           table
          </th>
          <th>
           type
          </th>
          <th>
           ……
          </th>
          <th>
           key
          </th>
          <th>
           ……
          </th>
          <th>
           ref
          </th>
          <th>
           rows
          </th>
          <th>
           extra
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           ……
          </td>
          <td>
           b
          </td>
          <td>
           ALL
          </td>
          <td>
           ……
          </td>
          <td>
          </td>
          <td>
           ……
          </td>
          <td>
          </td>
          <td>
           1000
          </td>
          <td>
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           a
          </td>
          <td>
           ref
          </td>
          <td>
           ……
          </td>
          <td>
           user_id
          </td>
          <td>
           ……
          </td>
          <td>
           b.user_id
          </td>
          <td>
           368
          </td>
          <td>
           Using where
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        <strong>
         强制join顺序的写法：
        </strong>
       </p>
       <table>
        <thead>
         <tr>
          <th>
           ……
          </th>
          <th>
           table
          </th>
          <th>
           type
          </th>
          <th>
           ……
          </th>
          <th>
           key
          </th>
          <th>
           ……
          </th>
          <th>
           ref
          </th>
          <th>
           rows
          </th>
          <th>
           extra
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           ……
          </td>
          <td>
           a
          </td>
          <td>
           ref
          </td>
          <td>
           ……
          </td>
          <td>
           stat_date
          </td>
          <td>
           ……
          </td>
          <td>
           const
          </td>
          <td>
           485228
          </td>
          <td>
           Using where
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           b
          </td>
          <td>
           ref
          </td>
          <td>
           ……
          </td>
          <td>
           user_id
          </td>
          <td>
           ……
          </td>
          <td>
           a.user_id
          </td>
          <td>
           1
          </td>
          <td>
           Using where
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        根据执行计划中的数据，可以说mysql的选择没有错。原有写法需要读取的数据大致是1000 * 368约合37万，修改写法则是48万，修改写法读取的代价更大。但实际运行情况则是修改写法快过原来写法数倍。
       </p>
       <p>
        不过，这个情况却不能随时重现。真要把这两个表写入空表并且重建索引再来查询，会发现
        <code>
         straight_join
        </code>
        的结果确实会更慢，也就是说在初始状态下，mysql的判断是对的。所以这样的问题只在日常运营中才会发生，无法重现，却是真实存在的，而且碰到类似这一类的应用场景，则必然发生。
       </p>
       <p>
        究其原因，在这种情况下，由于数据不是一次性建成，而是按天陆续写入，所以
        <code>
         user_pv_byday
        </code>
        的
        <code>
         user_id
        </code>
        索引会进行反复的修改，造成索引碎片，极端严重的情况下还会导致索引完全失效。而
        <code>
         stat_date
        </code>
        上的索引由于是每天递增，所以完全没有碎片问题，而且读取数据是还是顺序读取，效率自然要高不少。另外，根据实际情况的观察，随着数据的积累，上面执行计划中368这个值还会变得更小，也就是统计信息会越来越不准确。
       </p>
       <p>
        总之，mysql的执行计划在大部分情况下是没问题的，但是随着数据的不断积累修改，会逐渐出现mysql所不了解的细节，影响优化器的正常判断。这个时候如果能对表做一下重建也能让事情回到正轨，但是很多时候没有这个权限或者条件去做（比如你不是DBA，没有这种操作权限；或者表太大，没有完整的时间段可以操作）。那么强制索引使用就成了开发人员一个低成本的解决方案。
       </p>
       <h1 id="过多的join">
        过多的join
       </h1>
       <p>
        在mysql中，需要join的表如果太多，会对性能造成很显著的下降。同样，举例说明。
       </p>
       <p>
        首先生成一个表（表名
        <code>
         test
        </code>
        ），这个表只有60条记录，6个字段，其中第一个字段为主键：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           pk
          </th>
          <th>
           c1
          </th>
          <th>
           c2
          </th>
          <th>
           c3
          </th>
          <th>
           c4
          </th>
          <th>
           c5
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           1
          </td>
          <td>
           11
          </td>
          <td>
           21
          </td>
          <td>
           31
          </td>
          <td>
           41
          </td>
          <td>
           51
          </td>
         </tr>
         <tr>
          <td>
           2
          </td>
          <td>
           12
          </td>
          <td>
           22
          </td>
          <td>
           32
          </td>
          <td>
           42
          </td>
          <td>
           52
          </td>
         </tr>
         <tr>
          <td>
           3
          </td>
          <td>
           13
          </td>
          <td>
           23
          </td>
          <td>
           33
          </td>
          <td>
           43
          </td>
          <td>
           53
          </td>
         </tr>
         <tr>
          <td>
           4
          </td>
          <td>
           14
          </td>
          <td>
           24
          </td>
          <td>
           34
          </td>
          <td>
           44
          </td>
          <td>
           54
          </td>
         </tr>
         <tr>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
          <td>
           ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        然后做一个查询：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914d8606699830" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914d8606699830-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914d8606699830-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914d8606699830-3">
                    3
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914d8606699830-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914d8606699830-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914d8606699830-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0004 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914dd426562396" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; &lt;span class="aggregate"&gt;count&lt;/span&gt;(*) 
&lt;span class="keyword"&gt;from&lt;/span&gt; test a1
&lt;span class="keyword"&gt;join&lt;/span&gt; test a2 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914dd426562396-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914dd426562396-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914dd426562396-3">
                    3
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914dd426562396-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914dd426562396-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a1
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914dd426562396-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a2
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0037 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        也就是说让test表跟自己关联。计算的结果显然是60，而且几乎不费时间。
       </p>
       <p>
        但是如果是这样的查询（十个
        <code>
         test
        </code>
        表关联），会花费多少时间？
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914e3078024876" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
2
3
4
5
6
7
8
9
10
11
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e3078024876-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e3078024876-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e3078024876-6">
                    6
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-7">
                    7
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e3078024876-8">
                    8
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-9">
                    9
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e3078024876-10">
                    10
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e3078024876-11">
                    11
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914e3078024876-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e3078024876-2">
                    <span class="crayon-cn">
                     2
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e3078024876-3">
                    <span class="crayon-cn">
                     3
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e3078024876-4">
                    <span class="crayon-cn">
                     4
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e3078024876-5">
                    <span class="crayon-cn">
                     5
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e3078024876-6">
                    <span class="crayon-cn">
                     6
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e3078024876-7">
                    <span class="crayon-cn">
                     7
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e3078024876-8">
                    <span class="crayon-cn">
                     8
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e3078024876-9">
                    <span class="crayon-cn">
                     9
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e3078024876-10">
                    <span class="crayon-cn">
                     10
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e3078024876-11">
                    <span class="crayon-cn">
                     11
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0009 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914e9117199655" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; &lt;span class="aggregate"&gt;count&lt;/span&gt;(*)
&lt;span class="keyword"&gt;from&lt;/span&gt; test a1
&lt;span class="keyword"&gt;join&lt;/span&gt; test a2 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a3 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a4 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a5 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a6 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a7 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a8 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a9 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)
&lt;span class="keyword"&gt;join&lt;/span&gt; test a10 &lt;span class="keyword"&gt;using&lt;/span&gt; (pk)&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-1">
                    1
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e9117199655-2">
                    2
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-3">
                    3
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e9117199655-4">
                    4
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-5">
                    5
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e9117199655-6">
                    6
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-7">
                    7
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e9117199655-8">
                    8
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-9">
                    9
                   </div>
                   <div class="crayon-num crayon-striped-num" data-line="crayon-57686494914e9117199655-10">
                    10
                   </div>
                   <div class="crayon-num" data-line="crayon-57686494914e9117199655-11">
                    11
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914e9117199655-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e9117199655-2">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a1
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e9117199655-3">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a2
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e9117199655-4">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a3
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e9117199655-5">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a4
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e9117199655-6">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a5
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e9117199655-7">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a6
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e9117199655-8">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a7
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e9117199655-9">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a8
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line crayon-striped-line" id="crayon-57686494914e9117199655-10">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a9
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                   </div>
                   <div class="crayon-line" id="crayon-57686494914e9117199655-11">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     join
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-e">
                     test
                    </span>
                    <span class="crayon-v">
                     a10
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     using
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-v">
                     pk
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0104 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        答案是：肯定超过5分钟。因为做了实际测试，5分钟还没有出结果。
       </p>
       <p>
        那么mysql到底在干什么呢？用show processlist去看一下运行时情况：
       </p>
       <table>
        <thead>
         <tr>
          <th>
           ID
          </th>
          <th>
           ……
          </th>
          <th>
           COMMAND
          </th>
          <th>
           TIME
          </th>
          <th>
           STATE
          </th>
          <th>
           INFO
          </th>
         </tr>
        </thead>
        <tbody>
         <tr>
          <td>
           121
          </td>
          <td>
           ……
          </td>
          <td>
           QUERY
          </td>
          <td>
           302
          </td>
          <td>
           statistics
          </td>
          <td>
           select count(*) from test a1 ……
          </td>
         </tr>
        </tbody>
       </table>
       <p>
        原来是处在
        <code>
         statistics
        </code>
        的状态。这个状态，根据mysql的解释是在根据统计信息去生成执行计划。当然这个解释肯定是没有追根溯源。实际上mysql在生成执行计划的时候，其中有一个步骤，是确定表的join顺序。默认情况下，mysql会把所有join顺序全部排列出来，依次计算各个join顺序的执行代价并且取最优的那个。这样一来，n个表join会有n!种情况。十个表join就是10!，大概300万，所以难怪mysql要分析半天了。
       </p>
       <p>
        而在实际开发过程中，曾经出现过30多个表关联的情况（有10^32种join顺序）。一旦出现，花费在statistics状态的时间往往是在1个小时以上，这还只是在表数据量都非常小，需要做顺序分析的点比较少的情况下。至于出现这种情况的原因，无外乎我们需要计算的汇总报表的字段太多，需要从各种各样的地方计算出来数据，然后再把数据拼接起来，报表在维护过程中不断添加字段，又由于种种原因没有去掉已经废弃的字段，这样字段必定会越来愈多，实现这些字段计算就需要用更多的临时计算结果表去关联到一起，结果需要关联的表也越来越多，成了mysql无法承受之重。
       </p>
       <p>
        这个问题的解决方法有两个。从开发角度来说，可以控制join的表个数。如果需要join的表太多，可以根据业务上的分类，先做一轮join，把表的数量控制在一定范围内，然后拿到第一轮的join结果，再做第二轮全局join，这样就不会有问题了。从运维角度来说，可以设置
        <code>
         optimizer_search_depth
        </code>
        这个参数。它能够控制join顺序遍历的深度，进行贪婪搜索得到局部最优的顺序。一般有好多个表join的情况，都是上面说的相同维度的数据需要拼接成一张大表，对于join顺序基本上没什么要求。所以适当的把这个值调低，对于性能应该说没有影响。
       </p>
       <h1 id="列存储引擎Infobright">
        列存储引擎Infobright
       </h1>
       <p>
        Infobright是基于mysql的存储引擎，具有列存储/列压缩和知识网格等特性，比较适合数据仓库的计算。使用起来也不需要考虑索引之类的问题，非常方便。不过经过一段时间的运用，也发现了个别需要注意的问题。
       </p>
       <p>
        一个问题和myisam类似，不要取不需要的数据。这里说的不需要的数据，包括不需要的列（Infobright的使用常识。当然行存储也要注意，只不过影响相对比较小，所以没有专门提到），和不需要的行（行数是可以扩展的，行存储一行基本上都能存在一个存储单元中，但是列存储一列明显不可能存在一个存储单元中）。
       </p>
       <p>
        第二个问题，就是Infobright在长字符检索的时候并不给力。一般来说，网站的访问日志中会有URL字段用来标识访问的具体地址。这样就有查找特定URL的需求。比如我要在一个日志表中查找某种类型的url的访问次数：
       </p>
       <figure class="highlight">
        <table>
         <tbody>
          <tr>
           <td class="gutter">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914f2736774415" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               1
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914f2736774415-1">
                    1
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914f2736774415-1">
                    <span class="crayon-cn">
                     1
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0004 seconds] -->
           </td>
           <td class="code">
            <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
            <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686494914f8604548460" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
             <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
              <span class="crayon-title">
              </span>
              <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
               <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-wrap-button" title="切换自动换行">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-expand-button" title="点击展开代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-copy-button" title="复制代码">
                <div class="crayon-button-icon">
                </div>
               </div>
               <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
                <div class="crayon-button-icon">
                </div>
               </div>
              </div>
             </div>
             <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
             </div>
             <div class="crayon-plain-wrap">
              <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
               &lt;span class="operator"&gt;&lt;span class="keyword"&gt;select&lt;/span&gt; &lt;span class="aggregate"&gt;count&lt;/span&gt;(*) &lt;span class="keyword"&gt;from&lt;/span&gt; log &lt;span class="keyword"&gt;where&lt;/span&gt; url &lt;span class="keyword"&gt;like&lt;/span&gt; &lt;span class="string"&gt;'%mysql%'&lt;/span&gt;;&lt;/span&gt;
              </textarea>
             </div>
             <div class="crayon-main" style="">
              <table class="crayon-table">
               <tbody>
                <tr class="crayon-row">
                 <td class="crayon-nums " data-settings="show">
                  <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                   <div class="crayon-num" data-line="crayon-57686494914f8604548460-1">
                    1
                   </div>
                  </div>
                 </td>
                 <td class="crayon-code">
                  <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                   <div class="crayon-line" id="crayon-57686494914f8604548460-1">
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "operator"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     select
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "aggregate"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     count
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     (
                    </span>
                    <span class="crayon-o">
                     *
                    </span>
                    <span class="crayon-sy">
                     )
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     from
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     log
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     where
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-v">
                     url
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "keyword"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-v">
                     like
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-h">
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-e">
                     span
                    </span>
                    <span class="crayon-t">
                     class
                    </span>
                    <span class="crayon-o">
                     =
                    </span>
                    <span class="crayon-s">
                     "string"
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-s">
                     '%mysql%'
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                    <span class="crayon-sy">
                     ;
                    </span>
                    <span class="crayon-o">
                     &lt;
                    </span>
                    <span class="crayon-o">
                     /
                    </span>
                    <span class="crayon-v">
                     span
                    </span>
                    <span class="crayon-o">
                     &gt;
                    </span>
                   </div>
                  </div>
                 </td>
                </tr>
               </tbody>
              </table>
             </div>
            </div>
            <!-- [Format Time: 0.0032 seconds] -->
           </td>
          </tr>
         </tbody>
        </table>
       </figure>
       <p>
        类似这样在一个长字符串里面检索子串的需求，Infobright的执行时间测试下来是myisam的1.5-3倍。
        <br/>
        至于速度慢的原因，这里给出一个简要的解释：Infobright作为列式数据库使用了列存储的常用特性，就是压缩（列式数据库的压缩率一般要能做到10%以内，Infobright也不例外）。另外为了加快查找速度，它还使用了一种叫知识网格检索方式，一般情况下能够极大的减少需要读取的数据量。关于知识网格的原理已经超出了本篇文章的讨论篇幅，可以看
        <a href="http://www.cnblogs.com/inmanhust/archive/2010/05/08/1730343.html" target="_blank">
         这里
        </a>
        了解。但是在查询url的时候，知识网格的优点无法体现出来，但是使用知识网格本身带来的检索代价和解压长字符串的代价却仍然存在，而且比查询一般的数字类字段要来的大的多。
       </p>
       <p>
        解决办法有几种，比如
        <a href="http://www.infobright.org/images/uploads/blogs/how-to/How_To_Efficiently_Search_Strings_in_Infobright.pdf" target="_blank">
         官方的方案
        </a>
        是把长字符串MD5成一个数字，查询的时候加上数字作为补充查询条件。而
        <a href="http://weibo.com/1699016425/zzPJbzQFz" target="_blank">
         这条微博
        </a>
        给出的方法是进行分词然后再整数化。这些方案相对来说比较复杂，而我尝试过一种简单的解决方案（不过也有相当的局限性），就是根据这个长字段排序后再导入。这样一来按照该字段查询时，通过知识网格就能够屏蔽掉比较多的“数据包”（Infobright的数据压缩单元），而未排序的情况下符合条件的数据散布在各个“数据包”中，其解压工作量就大得多了。使用这个方法进行查询，测试下来其执行时间就只有mysql的0.5倍左右了。
       </p>
       <p>
       </p>
       <p>
        文章出处：
        <a href="http://sunyi514.github.io/2013/04/30/%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93%E4%B8%AD%E7%9A%84sql%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%EF%BC%88mysql%E7%AF%87%EF%BC%89/">
         肥男爱肉
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20517.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/07/t012366e61c52d9046b-300x228.png"/>
        </a>
        <a class="link" href="http://dataunion.org/20517.html" rel="bookmark" title="MySQL索引背后的数据结构及算法原理">
         MySQL索引背后的数据结构及算法原理
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20229.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/07/t012366e61c52d9046b-300x228.png"/>
        </a>
        <a class="link" href="http://dataunion.org/20229.html" rel="bookmark" title="8 个不得不说的 MySQL 陷阱">
         8 个不得不说的 MySQL 陷阱
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20094.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/07/t012366e61c52d9046b-300x228.png"/>
        </a>
        <a class="link" href="http://dataunion.org/20094.html" rel="bookmark" title="老叶观点：MySQL开发规范之我见">
         老叶观点：MySQL开发规范之我见
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20037.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/07/t01cbbd7ae2c54cab40.png"/>
        </a>
        <a class="link" href="http://dataunion.org/20037.html" rel="bookmark" title="记一次苦逼的SQL查询优化">
         记一次苦逼的SQL查询优化
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F7603.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/7603.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/7603.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>